<?php

class ssController extends AppController
{
    private $orderId = 'QIAO-201804130045';

    /**
     * 获取门店列表
     */
    public function get_shop_listAction(){
        $sse = new SSExpressClass(true);
        $info = $sse ->get_shop_list();
        echo '<pre>';
        var_dump($info);
    }


    /**
     * 添加修改门店
     */
    public function add_shopAction(){
        $sse = new SSExpressClass(true);
//        $parameter['thirdStoreId'] = '1002';
//        $parameter['storeName'] = '长宁店';
//        $parameter['cityName'] = '上海市';
//        $parameter['phone'] = '17321295203';
//        $parameter['address'] = '淞虹路258号';
//        $parameter['addressDetail'] = '4层3号楼';
//        $parameter['latitude'] = '31.2182700895';
//        $parameter['longitude'] = '121.3592290878';
        $parameter['goodType'] = 1;
        $info = $sse ->add_shop($parameter);
        echo '<pre>';
        var_dump($info);
    }


    /**
     * 发送订单详情 计费
     */
    public function billingAction(){
        $sfe = new SSExpressClass(true);
        $orderid = $this->orderId;
        $parameter['cityName'] = '北京市';          # 商家订单ID

        # 发件人信息
        //        $parameters['thirdStoreId'] = "{$parameter['deliver_store_id']}";                                     # 宅配门店编号 由添加店铺接口添加 对应  storeId
//        $parameters['storeId'] = $parameter['deliver_express_id'];                                           # 门店编号 由添加店铺接口添加的闪送门店编号 对应后台门店需要设置

        $parameter['sender']['fromAddress'] = '博彦科技大厦';             # 发件地址(来自百度地图)
        $parameter['sender']['fromAddressDetail'] = '4层101';             # 发件详细地址(用户输入)
        $parameter['sender']['fromSenderName'] = '小张';                  # 发件人(长度<=30英文字符或数字)
        $parameter['sender']['fromMobile'] = '13693100472';             # 发件人手机号
        $parameter['sender']['fromLatitude'] = '40.054759';             # 发件百度坐标(经度)
        $parameter['sender']['fromLongitude'] = '116.289086';             # 发件百度坐标(纬度)

        $parameter['receiverList'][0]['orderNo'] = $this->orderId;                      # 合作伙伴订单号
        $parameter['receiverList'][0]['toAddress'] = '望京';                      #  收件地址(取百度地图)
        $parameter['receiverList'][0]['toAddressDetail'] = '2楼';                      # 收件详细地址(用户输入)
        $parameter['receiverList'][0]['toLatitude'] = '40.004532';                      # 收件百度坐标(纬度)
        $parameter['receiverList'][0]['toLongitude'] = '116.475304';                      # 收件百度坐标(经度)
        $parameter['receiverList'][0]['toReceiverName'] = 'Ethan';                      # 收件人
        $parameter['receiverList'][0]['toMobile'] = '17321295203';                      # 收件人手机号,如果是隐私号此为主机号
        $parameter['receiverList'][0]['goodType'] = 1;                      # 发件类型（发件类型，1:餐饮;2:文件;3:蛋糕;4:鲜花;5:零食;6:其他;7:生鲜；8:数码；9:商超）
        $parameter['receiverList'][0]['weight'] = 1;                      # 物品重量(公斤)
        $parameter['receiverList'][0]['remarks'] = ' goods';                      # 备注
        $parameter['distributeCrowd'] = false;

        $info = $sfe ->billing($parameter);
        echo '<pre>';
        var_dump($info);
    }


    /**
     * 发送订单 19053010344564967
     */
    public function send_parameterAction(){
        $sfe = new SSExpressClass(true);
        $parameter['issOrderNo'] = '19053010344564967';                      # 闪送订单号
        $info = $sfe ->send_parameter($parameter);
        echo '<pre>';
        var_dump($info);
    }

    /**
     * 发送订单 加小费
     */
    public function additionOrderAction(){
        $sfe = new SSExpressClass(true);
        $parameter['issOrderNo'] = '19053010344564967';                      # 闪送订单号
        $parameter['additionAmount'] = 2000;                                # 单位 分
        $info = $sfe ->additionOrder($parameter);
        echo '<pre>';
        var_dump($info);
    }

    /**
     * 查询订单
     */
    public function queryAction(){
        $sfe = new SSExpressClass(true);
        $parameter['issOrderNo'] = '19053010344564967';                      # 闪送订单号
        $parameter['orderNo'] = $this->orderId;                                # 订单号
        $info = $sfe ->query($parameter);
        echo '<pre>';
        var_dump($info);
    }

    /**
     * 查询闪送员位置
     */
    public function courierAction(){
        $sfe = new SSExpressClass(true);
        $parameter['issOrderNo'] = '19053010344564967';                      # 闪送订单号
        $parameter['orderNo'] = $this->orderId;                                # 订单号
        $info = $sfe ->courier($parameter);
        echo '<pre>';
        var_dump($info);
    }

    /**
     * 订单取消
     */
    public function cancelAction(){
        $sfe = new SSExpressClass(true);
        $parameter['issOrderNo'] = '19053010344564967';                      # 闪送订单号
        $parameter['orderNo'] = $this->orderId;                                # 订单号
        $info = $sfe ->cancel($parameter);
        echo '<pre>';
        var_dump($info);
    }


    /**
     * 查询余额
     */
    public function accountAction(){
        $sfe = new SSExpressClass(true);
        $info = $sfe ->account();
        echo '<pre>';
        var_dump($info);
    }


    /**
     * 回调订单状态
     * 订单状态,20:已支付，系统派单中，待抢单；30:骑手已抢单，取货中；40:骑手已取货，闪送中；50:闪送完成；60:已取消
     */
    public function syncstatusAction(){
        $body = file_get_contents('php://input');
        file_put_contents('logs/SSgetcallback',"$body".PHP_EOL,FILE_APPEND);
        $returnInfo = json_decode($body,true);
        if($returnInfo['status'] == 20 || $returnInfo['status'] == 30 || $returnInfo['status'] == 40 || $returnInfo['status'] == 50 || $returnInfo['status'] == 60){
            $return = ["status"=>200,"msg"=>"订单状态同步成功"];
            echo  json_encode($return);
        }
    }
}
